package com.csx.base.concurrency.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p> what does this class do ? </p>
 *   本案例为 ThreadPoolExecutor 的使用案例,主要包括:
 *     1. ThreadPoolExecutor.execute 方法的使用
 *     2. ThreadPoolExecutor.submit 方法的使用
 *     3. ThreadPoolExecutor.invokeAll 方法的使用
 *     4. ThreadPoolExecutor.invokeAny 方法的使用
 *     5. ThreadPoolExecutor.shutdown 方法的使用
 *     6. ThreadPoolExecutor.其它获取基础数据的方法的使用
 * <p> How does it work ?</p>
 * <p> Why does it do this ?</p>
 *
 * @author cuisongxu
 * @date 2024/12/7 周六 9:34
 */
public class ThreadPoolExecutorTest {

    private static final AtomicInteger threadPoolThreadIndex = new AtomicInteger(1);
    private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            5,
            10,
            300,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(100),
            r -> new Thread(r, "My Executor Thread " + threadPoolThreadIndex.getAndIncrement()),
            new ThreadPoolExecutor.AbortPolicy()
    );


    public void testExecute() {
        for (int i = 0; i < 100; i++) {
            Runnable task = () -> System.out.println(Thread.currentThread().getName() + " 执行任务");
            executor.execute(task);
        }
    }

    public static void main(String[] args) {



    }


}
